
#ifndef __RT_CRYPTO_H__
#define __RT_CRYPTO_H__

#include "RtDefines.h"

extern "C"
{

/*****************************************************************************
 * Description:	
 *   This function is to encrypt or decrypt data stream using AES cipher. 
 *   The caller of the function should provide enough memory buffer for the 
 *   output data stream. For stream cipher mode, output data length value is 
 *   identical to input data length. While for block cipher mode, output data 
 *   length may be at most up to (iInDataLength+19-(iInDataLength+3)%16) bytes.
 *
 * Input : 
 *   lpInData: input data stream. 
 *   iInDataLength: input data stream length, in bytes.
 *   lpKey: encryption key. 
 *   iKeyLength: encryption key length.
 *   bEncrypt: if true encrypt, else decrypt. 
 *   bStream: if true encrypt with stream mode, else with block mode.
 *
 * Output: 
 *   lpOutData: output data stream. 
 *   iOutDataLength: output data stream length, in bytes. The caller of the 
 *   function should provide enough memory buffer for the output data stream. 
 *     
 * Return: 
 *   0 for success, otherwise failure.
 *****************************************************************************/	
RT_API_EXPORT RtResult RtCryptoEncrypt(
		const unsigned char* lpInData,
		int	iInDataLength,
		const unsigned char* lpKey,
		int iKeyLenght,
		bool bEncrypt,
		unsigned char* lpOutData,
		int& iOutDataLength,
		bool bStream = false);

/*****************************************************************************
 * Description:	
 *   Release memory buffer that has been allocated by other security APIs. 
 *
 * Input : Buffer address p.
 * Output: None.
 * Return: None.
 *
 * NOTE:
 *   It is the responsibility of users of the security module to release 
 *   memory buffer that was allocated by other security APIs. 
 *****************************************************************************/	
//CM_OS_EXPORT void RtCryptoFree(void* p);

typedef enum {
	RT_SHA1 = 1,
	RT_SHA256,
	RT_SHA512,
} RtMdType;

RT_API_EXPORT unsigned char* RtSha(
		RtMdType inType, 
		const unsigned char* inData, 
		size_t inDataLen, 
		unsigned char* outMd);

RT_API_EXPORT unsigned char* RtHmac(
		RtMdType inType, 
		const void* inKey, 
		int inKeyLen,
		const unsigned char* inData, 
		size_t inDataLen, 
		unsigned char* outMd,
		unsigned int* outMdLen);

}

#endif // __RT_CRYPTO_H__
